package com.yangzheandroid.rxmvp.view.handler;

import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yangzhe.okhttputils.OkHttpUtils;
import com.yangzheandroid.retrofitutils.utils.LogUtil;
import com.yangzheandroid.rxmvp.R;
import com.yangzheandroid.rxmvp.base.BaseActivity;
import com.yangzheandroid.rxmvp.base.SimpleActivity;

import java.io.IOException;

import butterknife.BindView;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class JdGoodsDeatailActivity extends SimpleActivity {

    public static final String TAG = JdGoodsDeatailActivity.class.getSimpleName();
    @BindView(R.id.activity_jd_goods_deatail)
    RelativeLayout mActivityJdGoodsDeatail;
    private TextView mTxt_test;


    public String getUrl = "http://test2.qsygo.com/interface.php/index/carousel";
    public String postUrl = "http://www.yangzheandroid.com:8080/SpeedServer/login";
    public String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyaWQiOiI4In0.Jfi1llegQ0G5ZpBXe3f9HSjNoyze6AW_BCaW3U4SINM";
    public String userId = "8";

    @Override
    protected void onDestroy() {
        super.onDestroy();
        OkHttpUtils.getInstance().cancelTag(this);
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_jd_goods_deatail;
    }

    @Override
    protected void initEventAndData() {
        mTxt_test = (TextView) findViewById(R.id.txt_test);
        mTxt_test.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

//                OkHttpUtils.post(postUrl)
//                        .tag(this)
//                        .params("username", "yangzhe008")
//                        .params("password", "123")
//                        .execute(new StringCallback() {
//                            @Override
//                            public void onResponse(String response) {
//                                LogUtil.e("test", "返回的结果为:  " + response);
//                            }
//                        });

//                OkHttpUtils.put(postUrl)
//                        .tag(this)
//                        .params("username", "yangzhe008")
//                        .params("newpassword", "1234")
//                        .params("confirmpassword", "1234")
//                        .params("token", token)
//                        .params("userId", userId)
//                        .execute(new StringCallback() {
//                            @Override
//                            public void onResponse(String response) {
//                                LogUtil.e("test", "返回的结果为:  " + response);
//                            }
//                        });

//                OkHttpUtils.delete(postUrl)
//                        .tag(this)
//                        .params("token", token)
//                        .params("userId", userId)
//                        .execute(new StringCallback() {
//                            @Override
//                            public void onResponse(String response) {
//                                LogUtil.e("test", "返回的结果为:  " + response);
//                            }
//                        });

                OkHttpClient client = new OkHttpClient();

                Request request = new Request.Builder()
                        .url(getUrl)
                        .build();

                client.newCall(request).enqueue(new Callback() {
                    @Override
                    public void onFailure(Call call, IOException e) {
                        LogUtil.e(TAG, "错误为: " + e);
                    }

                    @Override
                    public void onResponse(Call call, Response response) throws IOException {
                        LogUtil.e(TAG, "得到的结果为: " + response.body().string());
                    }
                });
            }
        });
    }


}
